
$(function(){
// 隐藏导航跟底部
	var windowheight = $(window).height();
	var margintop = (windowheight-$(".loginPublic").height())/2-55;
	$(".site-footer").css("display","none");
	$(".header").css("display","none");
	$(".loginPublic").css("margin-top",margintop);
});
/*发送验证码*/
$(document).on( "click", "#phonecode", function(e) {
		var usernameval = $(this).parent().parent().find("#rusername").val();
		var username = $(this).parent().parent().find("#rusername");
		var phonecode_href = $(".phonecode").attr("href");
		if(checkusername(username)){
			loading = layer.msg('加载中...', {icon: 16});
			$.post(phonecode_href, {"phone":usernameval, "_token":$("[name='_token']").val()}, function(data){
			}, 'json').error(function(data) {
				layer.close(loading);
			    var obj = $.parseJSON(data.responseText);
				$.each(obj.error_messages, function(i, item){
					$(".default-tip").hide();
					$(".error-tip").show();
					$(".error-tip").text(item[0]);
				});   
			}).success(function(data) {
				layer.close(loading);
				var time=60; 
				var id = setInterval(function() {
			    	if (time >0) {
			    		time--; 
			    		$('.phonecode').text("重新发送("+time+")");
			    		$(".phonecode").css("background-color","#b5b5b5");
			    		$(".phonecode").attr("id","");
			    	} else {
		  			    $(".phonecode").text("获取验证码");
		  			    $(".phonecode").css("background-color","#48b4ff");
		  			    $(".phonecode").attr("id","phonecode");
		  			 clearInterval(id)
		  			};
				},1000);
			});
			return true;
		}else{
			return false;
		}
})
/*提交绑定手机*/
$(document).on( "click", "#bind_phone", function(e) {
  var username = $(this).parent().parent().find("#rusername");
  var code = $(this).parent().parent().find("#rphonecode").val();
  var union_id = "";
  if (checkusername(username,1)) {
    if (code=="") {
      $(".error-tip").show();
      $(".error-tip").text("请输入验证码");
        return false;
    }
    var loading = layer.msg('加载中...', {icon: 16});
    var bind_phone_url = jumpUrl+"/bind/phone";
    var union_id =  JSON.parse(localStorage.getItem('union_id'));
    var platform =  JSON.parse(localStorage.getItem('platform'));
    $.post(bind_phone_url, {"phone":username.val(),"phonecode":code,"union_id":union_id, "platform":platform}, function(data){
    }, 'json').error(function(data) {
        var obj = $.parseJSON(data.responseText);
      $.each(obj.error_messages, function(i, item){
        $(".error-tip").show();
        $(".error-tip").text("绑定失败");
      });
    }).success(function(data) {
      var token = data.token;
      var post_id = JSON.parse(localStorage.getItem('post_id'));
      localStorage.setItem("token", JSON.stringify(token));
      // layer.msg(data.success_messages);
      // 判断是否律师入口进的登录
        var entrance = sessionStorage.getItem("entrance");
        if (entrance == "entrance") {
            if (data.data.status == 1) {
              location.href=jumpUrl+"/center/become_lawyer";
            }else if (data.data.status == 3) {
              location.href=jumpUrl+"/center/lawyer/main";
            }else{
              location.href=jumpUrl;
            }
          sessionStorage.removeItem("entrance");
          return false;
        }
        
        if(post_id != null){
          var post_id_status = true;
          localStorage.setItem("post_id_status", JSON.stringify(post_id_status));
        }
        var goback = sessionStorage.getItem("goback");
        if(goback == null || goback=="" || goback=="undefined"){
          location.href=jumpUrl;
        }else{
            location.href= goback;
        }
        sessionStorage.removeItem("goback");
    });
  }

});